﻿#pragma warning(disable: 4477)
#pragma warning(disable: 4996)
#pragma warning(disable: 6031)
#pragma warning(disable: 6054)
/*
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>

typedef double Real;
const Real PI = 3.14159265359;



typedef struct TContext_s
{
	int year;
	int n;
}TContext;

TContext context;

void read_data(TContext* ctx)
{
	scanf("%d", &ctx->year);
	scanf("%d", &ctx->n);
}

int count(int y)
{
	int s = 0;
	int a[10] = { 0 };
	for (int i = 0; i < 4; ++i)
	{
		++a[y % 10];
		y /= 10;
	}
	for (int i = 0; i < 10; ++i)
		if (a[i] > 0)
			++s;
	return s;
}

void do_task(TContext * ctx)
{
	int year = ctx->year;
	int k = 0;
	while (1)
	{
		if (count(year) == ctx->n)
		{
			printf("%d %04d\n", k, year);
			break;
		}
		++year;
		++k;
	}
	
}

void solve(TContext* ctx)
{
	read_data(ctx);
	do_task(ctx);
}

int main()
{
	freopen("D:/Develop/GitRepos/MOOC/浙江大学/数据结构/201906/DataStructure/M2019秋C入门和进阶练习集/7-134.txt", "r", stdin);
	solve(&context);
	return 0;
}
